<?php

namespace IDock\Insurance\QHIC\Response;

use IDock\Http\Response;
use IDock\IDock\IDockEnums;
use IDock\Insurance\QHIC\QHICEnums;
use IDock\Insurance\QHIC\Response\AllQHICResponse;
use IDock\Printer\VehicleModelPrinter;
use IDock\Printer\VehiclePrinter;

class VehicleModelResponse extends AllQHICResponse
{

    /**
     * @var VehicleModelPrinter $printer
     */
    public $printer = VehicleModelPrinter::class;

    public function printerInit(): Response
    {
        $body = $this->getBody() ?? [];
        $modelList = $body['VhlList'] ?? [];
        if (!$modelList) {
            return $this;
        }

        foreach ($modelList as $datum) {
            $vehiclePrinter = new VehiclePrinter();
            $vehiclePrinter->vehicleModelCode = $datum['CModelCde'] ?? '';
            $vehiclePrinter->brandName = $datum['CBrandCnmJY'] ?? '';
            $vehiclePrinter->vehicleExhaust = $datum['NDisplacement'] ?? '';
            $vehiclePrinter->vehicleName = $datum['CModelNme'] ?? '';
            $vehiclePrinter->vehiclePrice = $datum['NNewPurchaseValue'] ?? '';
            $vehiclePrinter->vehiclePriceWithOutTax = $datum['NNewPurchaseValue'] ?? '';

            $vehiclePrinter->vehicleSeat = $datum['NSeatNum'] ?? '';
            $vehiclePrinter->remark = $datum['CRemark'] ?? '';
            $vehiclePrinter->vehicleYear = $datum['CMarketDate'] ?? '';
            $vehiclePrinter->vehicleTonnage = $datum['NTonage'] ?? '0';
            $vehiclePrinter->wholeWeight = $datum['NCurbWt'] ?? '0';

            $vehiclePrinter->item['NNagoActualValue'] = $datum['NNagoActualValue'] ?? '';
            $vehiclePrinter->item['wholeWeight'] = $datum['NCurbWt'] ?? '';
            //能源类型
            $powerTypeCode = $datum['CFuelType'] ?? '0';
            $vehiclePrinter->energyTypeCode = array_search($powerTypeCode,QHICEnums::$energyType) ?: '';
            $vehiclePrinter->energyTypeName = IDockEnums::$energyType[$vehiclePrinter->energyTypeCode] ?? '';
            //新能源
            if (in_array($vehiclePrinter->energyTypeCode,['E02','E03','E04','E13'])) {
                $vehiclePrinter->isNewEnergy = '1';
            }
            $this->printer->setModelList($vehiclePrinter);
        }

        return $this;
    }
}
